package com.jewaton.authmanage.security;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

import com.jewaton.authmanage.mapper.UserInfoMapper;
import com.jewaton.authmanage.pojo.UserInfo;

public class CustomUserDetailServiceImpl implements UserDetailsService {
	
	@Autowired
	private UserInfoMapper userInfoMapper;

	@Override
	public UserDetails loadUserByUsername(String userName)
			throws UsernameNotFoundException {
		
		UserInfo user = userInfoMapper.findByUserName(userName) ; //123456
		if(user==null) 
			return user;
		if("admin".equals(userName)){
			user.setAuthoritiesOt(new String[]{"ROLE_ADMIN","ROLE_USER"});
			//user = new UserInfo("admin","e10adc3949ba59abbe56e057f20f883e",new String[]{"ROLE_ADMIN","ROLE_USER"});
		}else if("user".equals(userName)){
			user.setAuthoritiesOt(new String[]{"ROLE_USER"});
			//user = new UserInfo("user","e10adc3949ba59abbe56e057f20f883e",new String[]{"ROLE_USER"});
		}
        
		return user;
	}

}
